LIBS = libcurl gtk+-2.0 gthread-2.0
HAVE_XFCE4 = $(shell pkg-config --list-all | grep libxfce4panel-1.0 | wc -l)
ifneq ($(HAVE_XFCE4),0)
	LIBS += libxfce4panel-1.0
endif

CFLAGS = `pkg-config --cflags $(LIBS)`
LDFLAGS = `pkg-config --libs $(LIBS)`

common_OBJECTS = ic.o config.o
xfce_OBJECTS = xfce-ui.o
xfce_TARGET = xfce-icclient
tray_OBJECTS = tray-ui.o
tray_TARGET = tray-icclient
cui_OBJECTS = console-ui.o
cui_TARGET = cui-icclient

all_OBJECTS = $(common_OBJECTS) $(tray_OBJECTS) $(cui_OBJECTS)
ifneq ($(HAVE_XFCE4),0)
	all_OBJECTS += $(xfce_OBJECTS)
endif
all_TARGETS = $(tray_TARGET) $(cui_TARGET)
ifneq ($(HAVE_XFCE4),0)
	all_TARGETS += $(xfce_TARGET) 
endif
all_DEPEND = $(all_OBJECTS:.o=.d)

all: $(all_TARGETS)

$(cui_TARGET): $(cui_OBJECTS) $(common_OBJECTS)
	$(CC) $(LDFLAGS) -o $@ $^

$(xfce_TARGET): $(xfce_OBJECTS) $(common_OBJECTS)
	$(CC) $(LDFLAGS) -o $@ $^

$(tray_TARGET): $(tray_OBJECTS) $(common_OBJECTS)
	$(CC) $(LDFLAGS) -o $@ $^

clean:
	@rm -vf $(all_DEPEND)
	@rm -vf $(all_OBJECTS)
	@rm -vf $(all_TARGETS)

%.o: %.c %.d makefile
	$(CC) -c $(CFLAGS) -g -O0 --std=gnu99 -Wall -o $@ $<

%.d: %.c
	@echo Dependence for $<
	@$(CC) -M $(CFLAGS) $< > $@

-include $(all_DEPEND)